package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpCollectProductDiagnosisRecordBo;
import com.erp.gather.domain.vo.ErpCollectProductDiagnosisRecordVo;
import com.erp.gather.service.IErpCollectProductDiagnosisRecordService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 在线商品检测记录
 *
 * @author erp
 * @date 2023-12-12
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/collectProductDiagnosisRecord")
public class ErpCollectProductDiagnosisRecordController extends BaseController {

    private final IErpCollectProductDiagnosisRecordService iErpCollectProductDiagnosisRecordService;

    /**
     * 查询在线商品检测记录列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpCollectProductDiagnosisRecordVo> list(ErpCollectProductDiagnosisRecordBo bo, PageQuery pageQuery) {
        return iErpCollectProductDiagnosisRecordService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取在线商品检测记录详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpCollectProductDiagnosisRecordVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpCollectProductDiagnosisRecordService.queryById(id));
    }

    /**
     * 新增在线商品检测记录
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpCollectProductDiagnosisRecordBo bo) {
        return toAjax(iErpCollectProductDiagnosisRecordService.insertByBo(bo));
    }

    /**
     * 修改在线商品检测记录
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCollectProductDiagnosisRecordBo bo) {
        return toAjax(iErpCollectProductDiagnosisRecordService.updateByBo(bo));
    }

    /**
     * 删除在线商品检测记录
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpCollectProductDiagnosisRecordService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    /**
     * 美工处理页面
     */
    @GetMapping("/graphicProcessingRecordList")
    public TableDataInfo<ErpCollectProductDiagnosisRecordVo> graphicProcessingRecordList(String collectProductId, Integer status, PageQuery pageQuery) {
        return iErpCollectProductDiagnosisRecordService.graphicProcessingRecordList(collectProductId,status, pageQuery);
    }

    /**
     * 选择主图作为白底图
     */
    @GetMapping("/chooseMainImageAsWhite")
    public R<Object> chooseMainImageAsWhite(String imgUrl,Long collectProductId) {
        return iErpCollectProductDiagnosisRecordService.chooseMainImageAsWhite(imgUrl, collectProductId);
    }

    /**
     * 确认使用白底图
     */
    @GetMapping("/confirmUseWhite")
    public R<Object> confirmUseWhite(Long collectProductId) {
        return iErpCollectProductDiagnosisRecordService.confirmUseWhite(collectProductId);
    }

    /**
     * 批量确认白底图
     * @return
     */
    @GetMapping("/confirmAllUseWhite")
    public R<Object> confirmAllUseWhite() {
        return iErpCollectProductDiagnosisRecordService.confirmAllUseWhite();
    }

}
